package com.jjty.dataGenerator.jshjy.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.jjty.dataGenerator.jshjy.event.DataInsertEvent;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private final ApplicationEventPublisher eventPublisher;

    public MyMetaObjectHandler(ApplicationEventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        Object entity = metaObject.getOriginalObject();
        eventPublisher.publishEvent(new DataInsertEvent(this, entity));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 不需要更新填充
    }
}